let t = require;
let e = module;
let o = e.exports;
o.default = e.exports;

('use strict');
console.log('start'),
  Object.defineProperty(o, '__esModule', {
    value: !0
  }),
  (o.ResMrg = o.ResData = o.LoadResType = void 0);
var n,
  i = t('SoundMrg'),
  r = t('ConfigData'),
  a = t('GlobalEventMrg'),
  s = t('ClassUtils'),
  c = t('UIMrg'),
  l = t('Logger'),
  u = t('TimeMrg');
(function (t) {
  (t[(t.ATLAS = 1)] = 'ATLAS'),
    (t[(t.SOUND = 2)] = 'SOUND'),
    (t[(t.CONFIG = 3)] = 'CONFIG'),
    (t[(t.LOAD_USER_DATA = 4)] = 'LOAD_USER_DATA'),
    (t[(t.PREFAB = 5)] = 'PREFAB'),
    (t[(t.UI = 6)] = 'UI'),
    (t[(t.DIR = 7)] = 'DIR'),
    (t[(t.LOAD_FINISH = 8)] = 'LOAD_FINISH'),
    (t[(t.BUNDLE = 9)] = 'BUNDLE'),
    (t[(t.TEXTURE = 10)] = 'TEXTURE'),
    (t[(t.MATERIAL = 11)] = 'MATERIAL'),
    (t[(t.SCENE = 12)] = 'SCENE');
})((n = o.LoadResType || (o.LoadResType = {})));
var h = (function () {
  function t(t, e) {
    (this._url = t), (this._type = e);
  }
  return (
    Object.defineProperty(t.prototype, 'url', {
      get: function get() {
        return this._url;
      },
      enumerable: !1,
      configurable: !0
    }),
    Object.defineProperty(t.prototype, 'type', {
      get: function get() {
        return this._type;
      },
      enumerable: !1,
      configurable: !0
    }),
    t
  );
})();
o.ResData = h;
var p = (function () {
  function t() {}
  return (
    (t.addPreLoad = function (t, e) {
      void 0 === e && (e = null), this._preLoadResList.push(new h(t, e));
    }),
    (t.addBackeLoad = function (t, e) {
      void 0 === e && (e = null), this._backLoadResList.push(new h(t, e));
    }),
    (t.startBackLoad = function () {
      (t._index = 0), (this._isBackLoading = !0), this.nextBackLoad();
    }),
    (t.nextBackLoad = function () {
      if (t._index < t._backLoadResList.length) {
        var e = this._backLoadResList[t._index];
        switch (e.type) {
          case n.ATLAS:
            t.loadAtlas(e.url);
            break;

          case n.SOUND:
            t.loadSounds(e.url);
            break;

          case n.CONFIG:
            t.loadConfig(e.url);
            break;

          case n.PREFAB:
            t.loadPrefab(e.url);
            break;

          case n.UI:
            t.loadUI(e.url);
            break;

          case n.DIR:
            t.loadDir(e.url);
            break;

          case n.TEXTURE:
            t.loadTexture(e.url);
            break;

          case n.MATERIAL:
            t.loadMaterial(e.url);
            break;

          case n.SCENE:
            t.loadScene(e.url);
        }
      }
    }),
    (t.startLoadConfig = function () {
      (t._index = 0), (this._isLoadConfig = !0);
      for (var e = 0; e < t._preLoadResList.length; e++) {
        var o = this._preLoadResList[e];
        o.loaded ||
          o.type != n.CONFIG ||
          ((o.loaded = !0), t.loadConfig(o.url));
      }
    }),
    (t.startPreLoad = function () {
      this._isLoadConfig || (t._index = 0);
      for (var e = 0; e < t._preLoadResList.length; e++) {
        var o = this._preLoadResList[e];
        if (!o.loaded) {
          console.log(o.type);
          switch (((o.loaded = !0), o.type)) {
            case n.ATLAS:
              t.loadAtlas(o.url);
              break;

            case n.SOUND:
              t.loadSounds(o.url);
              break;

            case n.PREFAB:
              t.loadPrefab(o.url);
              break;

            case n.UI:
              t.loadUI(o.url);
              break;

            case n.DIR:
              t.loadDir(o.url);
              break;

            case n.TEXTURE:
              t.loadTexture(o.url);
              break;

            case n.MATERIAL:
              t.loadMaterial(o.url);
              break;

            case n.SCENE:
              t.loadScene(o.url);
          }
        }
      }
    }),
    (t.prototype.getSpriteAtlas = function (e) {
      return t._autoAtlasMap[e];
    }),
    (t.loadView = function (t, e, o, n) {
      cc.resources.load('View/' + e + '/' + t, cc.Prefab, function (t, e) {
        null == t && o && o.call(n, cc.instantiate(e));
      });
    }),
    (t.loadScene = function (e) {
      cc.director.preloadScene(
        e,
        function () {},
        function () {
          t.loadingProgress();
        }
      );
    }),
    (t.loadAtlas = function (e) {
      cc.resources.load(e, cc.SpriteAtlas, function (o, n) {
        var i = e.split('/'),
          r = i[i.length - 2];
        (t._autoAtlasMap[r] = n), t.loadingProgress();
      });
    }),
    (t.loadTexture = function (e) {
      cc.resources.load(e, cc.Texture2D, function () {
        t.loadingProgress();
      });
    }),
    (t.loadMaterial = function (e) {
      cc.resources.load(e, cc.Material, function () {
        t.loadingProgress();
      });
    }),
    (t.loadSounds = function (e) {
      cc.resources.load(e, cc.AudioClip, function (o, n) {
        i.SoundMrg.initSound(e, n), t.loadingProgress();
      });
    }),
    (t.loadConfig = function (e) {
      cc.resources.load(e, cc.Asset, function (e, o) {
        e ||
          (a.default.once(
            a.GlobalEvent.LoginSuccess,
            t.onLoginSuccessHandler,
            t
          ),
          r.default.init(o._buffer),
          a.default.emit(a.GlobalEvent.LOAD_CONFIG_FINISH),
          t.loadingProgress());
      });
    }),
    (t.onLoginSuccessHandler = function () {
      t.startPreLoad();
    }),
    (t.loadPrefab = function (e) {
      cc.resources.load(e, cc.Prefab, function () {
        t.loadingProgress(), t._prefabPools.set(e, []);
      });
    }),
    (t.loadUI = function (e) {
      var o = s.default.getClassName(e);
      if (null != o && null == c.UIMrg.getPanel(o)) {
        var n = e.RES;
        n
          ? cc.resources.load(
              'View/' + n.packName + '/' + n.viewName,
              null,
              function (o, n) {
                if (o) l.Logger.error(o.message);
                else if (null == c.UIMrg.getPanel(s.default.getClassName(e))) {
                  var i = cc.instantiate(n);
                  c.UIMrg.addPanel(e, i);
                }
                t.loadingProgress();
              }
            )
          : t.loadingProgress();
      }
    }),
    (t.loadDir = function (e) {
      cc.resources.loadDir(e, function () {
        t.loadingProgress();
      });
    }),
    (t.loadDataFinish = function () {
      t.loadingProgress();
    }),
    (t.loadingProgress = function () {
      t._index++,
        t._isBackLoading
          ? u.TimeMrg.timer.delayCall(t.nextBackLoad, t, 0.2)
          : (a.default.emit(
              a.GlobalEvent.LOADING_PROCESS,
              t._index / t._preLoadResList.length
            ),
            t._index >= t._preLoadResList.length &&
              u.TimeMrg.timer.delayCall(
                function () {
                  a.default.emit(a.GlobalEvent.LOADING_FINISH);
                },
                this,
                0.5
              ));
    }),
    (t.loadSprite = function (t, e) {
      t &&
        t.node &&
        cc.resources.load(e, cc.SpriteFrame, function (o, n) {
          o ? l.Logger.error('SpriteFrame', o, e) : (t.spriteFrame = n);
        });
    }),
    (t.loadSpriteByAtlas = function (t, e, o) {
      //   this._imgIcon, 'Atlas/Battle', this._data.icon;
      var n = this;
      let name = e + '/' + o;
      t &&
        cc.resources.load(name, cc.SpriteFrame, function (i, r) {
          if (i) l.Logger.warn('SpriteAtlas', i, e);
          else {
            t.spriteFrame = r;
            // var a = r.getSpriteFrame(o + '/spriteFrame');
            // a
            //   ? (t.spriteFrame = a)
            //   : n.loadSprite(t, e.substring(0, e.lastIndexOf('/') + 1) + o);
          }
        });
    }),
    (t.loadRemoteImg = function (t, e, o, n, i) {
      cc.assetManager.loadRemote(e, function (e, r) {
        if (e)
          return (
            l.Logger.error('err:' + JSON.stringify(e)),
            void (i && n && i.call(n))
          );
        t.spriteFrame.setTexture(r), o && n && o.call(n);
      });
    }),
    (t._preLoadResList = []),
    (t._backLoadResList = []),
    (t._autoAtlasMap = {}),
    (t._prefabPools = new Map()),
    t
  );
})();
(o.ResMrg = p), console.log('end');
module.exports = e.exports;
